package com.yhs.best;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;



public class GuideRaid extends Activity {

	int c = 1;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guideraid);
		
		Bundle b = getIntent().getExtras();
		int pagine = b.getInt("pagine");
		int raid = b.getInt("raid");
		TextView raidname = (TextView) findViewById (R.id.raidName);
		raidname.setText(tabname(raid,0));
		TextView raidinfo = (TextView) findViewById (R.id.raidInfo);
		filereader(raidinfo,raid,0);
		
		
		TabHost th = (TabHost) findViewById (R.id.raidtabhost);
		th.setup();
		TabSpec specs = th.newTabSpec("tag0");
		specs.setContent(R.id.tab1);
		specs.setIndicator("Raid Info");
		th.addTab(specs);

		int i=1;
		for(i = 1; i<=pagine; i= i + 1){
		c = addTab(th, raid, c) + 1;
		}
		
	}

	
	 public int addTab(TabHost th, int raid, int c) {
		 	final int count = c;
		 	final int r = raid;
		 	TabHost.TabSpec spec = th.newTabSpec("tag"+c);
		    
		    spec.setContent(new TabHost.TabContentFactory() {
		      public View createTabContent(String tag) {
		    	  TextView text = new TextView(GuideRaid.this);
		    	  filereader(text,r,count);
		    	  return(text); } });
		    spec.setIndicator(tabname(r, c));
		    th.addTab(spec);
		    return (count);
		  }


	 public void filereader(TextView tv, int cartella, int pagina){
		 final int pag = pagina;
		 final int car = cartella;
		 try{		
 			 InputStream is = getResources().getAssets().open("raid/"+car+"/"+pag+".html");
 				      InputStreamReader ir = new InputStreamReader(is);
 				      BufferedReader br = new BufferedReader(ir);
 				      String line;
 				      while((line = br.readLine()) != null){
 				    	  tv.append(Html.fromHtml(line));
 				      }
 				
 			} catch (FileNotFoundException e){
 				e.printStackTrace();
 			} catch (IOException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();}	 
	 }
	 
	 public String tabname(int raid, int count){
		 String name = null;
		 switch (raid){
		 case 0: { //chamber of the aspect
			 
		 break;}
		 case 1: { //ICC
			 switch (count) {
			 case 0: name = "Icecrown Cittadel"; break;
			 case 1: name = "Lord Marrowgar"; break;
			 case 2: name = "Lady Deathwhisper"; break;
			 case 3: name = "Gunship Battle"; break;
			 case 4: name = "Deathbringer Sarufang"; break;
			 case 5: name = "Festergut"; break;
			 case 6: name = "Rotface"; break;
			 case 7: name = "Professor Putricide"; break;
			 case 8: name = "Blood Prince Council"; break;
			 case 9: name = "Blood-Queen Lana'thel"; break;
			 case 10: name = "Valithria Dreamwalker"; break;
			 case 11: name = "Sindragosa"; break;
			 case 12: name = "The Lich King"; break;
			 } } break;
		 case 2: {	//Naxaramass
			 switch (count) {
			 case 0: name = "Naxaramass"; break;
			 case 1: name = "Anub'Rekhan"; break;
			 case 2: name = "Grand Widow Faerlina"; break;
			 case 3: name = "Maexxna"; break;
			 case 4: name = "Patcwerk"; break;
			 case 5: name = "Grobbulus"; break;
			 case 6: name = "Gluth"; break;
			 case 7: name = "Thaddius"; break;
			 case 8: name = "Instructor Razuvious"; break;
			 case 9: name = "Gothik the Harvester"; break;
			 case 10: name = "The four Horsemen"; break;
			 case 11: name = "Noth the plaguebringer"; break;
			 case 12: name = "Heigan the Unclean"; break;
			 case 13: name = "Loatheb"; break;
			 case 14: name = "Sapphiron"; break;
			 case 15: name = "Kel'Thuzad"; break;
			 } } break;
		 case 3: {	//Onyxia's Lair
			 switch (count) {
			 case 0: name = "Onyxia's Lair"; break;
			 case 1: name = "Onyxia"; break;
			 } } break;
		 case 4: {	//Trial of the Crusader
			 switch (count) {
			 case 0: name = "Trial of the Crusader"; break;
			 case 1: name = "Gormok the Impaler"; break;
			 case 2: name = "Acidmaw & Dreadscale"; break;
			 case 3: name = "icehowl"; break;
			 case 4: name = "Lord Jaraxxus"; break;
			 case 5: name = "The Faction Champions"; break;
			 case 6: name = "Twin Val'kyr"; break;
			 case 7: name = "Anub'arak"; break;
			 } } break;
		 case 5: {	//The Eye of Ethernity
			 switch (count) {
			 case 0: name = "The Eye of Ethernity"; break;
			 case 1: name = "Malygos"; break;
			 } } break;
		 case 6: {	//Ulduar
			 switch (count) {
			 case 0: name = "Ulduar"; break;
			 case 1: name = "Flame Leviathan"; break;
			 case 2: name = "Ignis the Furnace Master"; break;
			 case 3: name = "Razorscale"; break;
			 case 4: name = "XT-002 Deconstructor"; break;
			 case 5: name = "The Assembly of Iron"; break;
			 case 6: name = "Kologarn"; break;
			 case 7: name = "Auriaya"; break;
			 case 8: name = "Mimiron"; break;
			 case 9: name = "Freya"; break;
			 case 10: name = "Thorim"; break;
			 case 11: name = "Hodir"; break;
			 case 12: name = "General Vezax"; break;
			 case 13: name = "Yogg-Saron"; break;
			 case 14: name = "Algalon the Observer"; break;
			 } } break;
		 case 7: {	//Vault of Archavon
			 switch (count) {
			 case 0: name = "Vault of Archavon"; break;
			 case 1: name = "Archavon the Stone Watcher"; break;
			 case 2: name = "Emalon the Storm Watcher"; break;
			 case 3: name = "Koralon the Flame Watcher"; break;
			 case 4: name = "Toravon the Ice Watcher"; break;
			 } } break;
		 }
		 return name;
	 }
}
